﻿package com.cf.core.view{
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import com.cf.core.events.*;
	import com.cf.core.Utils.*;
	import com.cf.core.control.preload;
	public class SkinLoader extends Sprite{
		public function SkinLoader():void{}//fn
		
		private var __bg:*;
		public function get bg():*{return __bg}
		public function set bg(_o:*):void{__bg=_o}//fn
		
		private var _cmask:Sprite;
		private var _content:Sprite;
		private var inlineX:Number;
		private var inlineY:Number;
		private var inWidth:Number;
		private var inHeight:Number;
		private var inEllipse:Number;
		
		protected var __preload:preload=new preload();
		
		public function init(obj:Object):void{
			inlineX=0;
			inlineY=0;
			inWidth=0;
			inHeight=0;
			inEllipse=0;
			// loader is setting part 1
			if( obj.inline!=undefined ){ inlineX = Number(obj.inline); inlineY = Number(obj.inline); }//fn
			if( obj.inlineX!=undefined ){ inlineX = Number(obj.inlineX); }//fn
			if( obj.inlineY!=undefined ){ inlineY = Number(obj.inlineY); }//fn
			// background of loader
			if( obj.bg!=undefined ){
				bg = obj.bg;
				// PreDefine default value of _content's setting
				// get those inline's value
				inWidth = bg.width - inlineX;
				inHeight = bg.height - inlineY;
				// trace("mask default width/height is "+ inWidth +"/"+ inHeight);
			}//if
			this.addChildAt( bg, 0 );
			// loader is setting part 2
			if( obj.inWidth!=undefined ){ inWidth = Number(obj.inWidth); }//fn
			if( obj.inHeight!=undefined ){ inHeight = Number(obj.inHeight); }//fn
			_content = new Sprite();
			_content.x = inlineX;
			_content.y = inlineY;
			
			if( obj.inEllipse!=undefined){ inEllipse = Number(obj.inEllipse); }
			_cmask = new Sprite();
			_cmask.graphics.clear();
			_cmask.graphics.beginFill(0xD4D4D4); // grey color
			// x, y, width, height, ellipseW, ellipseH
			_cmask.graphics.drawRoundRect(0, 0, inWidth, inHeight, inEllipse, inEllipse);
			_cmask.graphics.endFill();
			_cmask.x = inlineX;
			_cmask.y = inlineY;
			_content.mask = _cmask;
			this.addChild( _cmask);
			this.addChild( _content);
			loadthis(obj);
		}//fn
		public function RELEASE():void{
			__preload.RELEASE();
		}//fn
		public function loadthis(_file:Object):void{
			__preload=new preload();
			__preload.init(_file);
			__preload.addEventListener(LoadEvent.ONLOAD, handleOnload);
			__preload.load();
			tools.emptySprite(_content);
			__preload.rst.x = inWidth/2;
			__preload.rst.y = inHeight/2;
			_content.addChild( __preload.rst ); // preloader anime
		}//fn
		
		private function handleOnload(e:LoadEvent):void{
			tools.emptySprite(_content);
			_content.addChild( __preload.rst ); // Url loaded
			// trace("SkinLoader Onload : "+ __preload.rst);
			__preload.removeEventListener(LoadEvent.ONLOAD, handleOnload);
		}//fn
	}//class
}//package